<template>
    <div class="allNav" :class="{ isShow }">
        <div class="top">
            <div @click="closeAllNav" class="close"/>
            <div class="language"></div>
        </div>
        <div class="logo">
            <img :src="logo">
        </div>
        <div class="navList">
            <NuxtLink class="main" key="1" to="/">首页</NuxtLink>
            <div
              class="item"
              v-for="item in navList"
              :key="item.id">
                <div class="main" @click="showMore(item.id)">
                    <span>{{ item.name }}</span>
                </div>
                <div class="moreNav" :class="{ 'showMoreNav' : showNavParent === item.id }">
                    <div>
                        <NuxtLink
                          class="more-item"
                          v-for="m in item.children"
                          :to="item.path + '?id=' + m.id"
                          :key="m.id">
                            <span>{{ m.name }}</span>
                        </NuxtLink>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import logo from '@/assets/images/logo.png'
import { useRoute } from 'vue-router'
const route = useRoute()
defineProps({
    navList:{
        type: Array<{
            id: number,
            path: string,
            name: string,
            children: Array<{
                id: number,
                name: string,
            }>
        }>,
        required: true,
    }
})
const isShow = defineModel<boolean>()
watch(()=>route.fullPath, _ => closeAllNav())
const closeAllNav = ():void=>{
    isShow.value = false
    showNavParent.value = 0
}


const showNavParent:Ref<number> = ref(0)
const showMore = (id:number):void => {
    showNavParent.value === id ? showNavParent.value = 0 :
    showNavParent.value = id
}
</script>

<style lang="scss" scoped>
.top{
    padding: 10px;
    .close{
        width: 25px;
        height: 25px;
        background: url('@/assets/images/close-icon.png') no-repeat center center;
        background-size: cover;
    }
}
.allNav{
    &.isShow{
        height: 100%;
    }
    transition: all 0.3s;
    position: fixed;
    top: 0;
    left: 0;
    height: 0;
    width: 100%;
    overflow: hidden;
    right: 0;
    background:url('@/assets/images/mobile-cover-nav-bg.jpeg') no-repeat center center;
    background-size: 110%;
    z-index: 999;
    .top{
        height: 40px;
    }
    .logo{
        text-align: center;
    }
    .navList{
        padding: 15px;
        padding-top: 30px;
        .main{
            width: 100%;
            padding:20px 0;
            border-bottom: 1px solid #464646;
            font-size: 16px;
            color: #fff;
            display: -ms-flexbox;
            display: flex;
            -ms-flex-flow: row nowrap;
            flex-flow: row nowrap;
            display: flex;
            flex-direction: column;
        }
        .moreNav{
            &.showMoreNav{
                grid-template-rows: 1fr;
            }
            display: grid;
            grid-template-rows: 0fr;
            transition: all 0.3s;
            > div{
                overflow: hidden;
                .more-item{
                    display: block;
                    padding: 12px 0px;
                    border-bottom: 1px solid #2e2e2e;
                    color: rgba(255, 255, 255, .5);
                    font-size: 12px;
                }
            }
        }
    }
}
</style>